
#include "stdafx.h"
#include "ifetcher.h"
#include "defs.h"
#include "symtbl.h"
int _tmain(int argc, LPCTSTR argv[]) 
{
	if (argc<2)
	{
		PRINTF(_T("Usage: disasm <file name>\n"));
		return 1;
	}

	CIFetcherFileMap fetcher;

	if(0!=fetcher.Open(argv[1],0,0,0))
	{
		PRINTF(_T("open file %s failed.\n"),argv[1]);
		return 1;
	}

	INSN_BASIC_INFO insn;
	while(fetcher.fetch(&insn)==FETCH_SUCCESS)
	{
		char buffer[1024];

		char *sym=sym_lookup(fetcher.get_fetch_eip());
		int len;
		
		if(sym)
			len=sprintf(buffer,"%s:\n",sym);
		else len=0;

		len+=disasm(buffer+len,&insn);
		buffer[len]=0;

		printf("%s\n",buffer);
	}
}